package net.tv90.bfmccore.listener;

import net.tv90.bfmccore.battlepack.EnumBattlepackLevel;
import net.tv90.bfmccore.constant.RewardConstant;
import net.tv90.bfmccore.event.ServiceStarGetEvent;
import net.tv90.bfmccore.util.HUD.HUD;
import net.tv90.bfmccore.util.HUD.HUDDelayedQueue;
import net.tv90.bfmccore.util.HUD.Text;
import net.tv90.bfmccore.util.vector.Vector2i;
import org.bitterorange.flansmodslain.actions.Money;
import org.bitterorange.flansmodslain.actions.Point;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.ArrayList;
import java.util.List;

import static net.tv90.bfmccore.battlepack.Battlepack.getBattlepack;
import static net.tv90.bfmccore.helper.FactionHelper.getFaction_Lang;

public class ServiceStarListener implements Listener {

    @EventHandler
    public void onServiceStarGet(ServiceStarGetEvent e) {
        Player player = e.getPlayer();
        String weapon = e.getWeapon();
        Bukkit.broadcastMessage("§e[管理员]玩家" + player.getName() + "(" + getFaction_Lang(player) + ")" + "获得了" + weapon + "武器的勤务之星,目前共有" + e.getStarCount() + "颗。");
        player.sendMessage("§e[管理员]你使用" + weapon + "武器完成了" + e.getStarCount() * 100 + "次击杀,获得该武器的勤务之星,目前共" + e.getStarCount() + "颗。");

        int point = (int) (100 * RewardConstant.POINT_MAGNIFICATION);
        int money = (int) (200 * RewardConstant.MONEY_MAGNIFICATION);
        Point.add(player, point);
        Money.give(player, money);
        player.sendMessage("§e[管理员]你获得" + point + "军衔积分和" + money + "游戏币的奖励");

        Text text = new Text(new Vector2i(-1, 125), weapon + "勤务之星", 1.5D);
        Text text2 = new Text(new Vector2i(-1, 145), e.getStarCount() * 100 + " 击杀数", 1.5D);
        List<Text> list = new ArrayList<>();
        list.add(text);
        list.add(text2);
        HUD hud = new HUD(player, "[local]BFMC/Service_Star.png", "custom.Unlock_Medal", list,
                new Vector2i(-1, 20), new Vector2i(110, 110), 5);
        HUDDelayedQueue.addHUD(player, hud);

        if (e.getStarCount() == 1) {
            getBattlepack(player, EnumBattlepackLevel.WEAPON);
        }
    }
}
